/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.login;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.i.k;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.h.g;
import org.json.JSONObject;

public class d {
    private Context a;
    private Intent b;
    private String c = null;

    public d(Context paramContext, Intent paramIntent) {
        this.a = paramContext;
        this.b = paramIntent;
    }

    public void a(String paramString) {
        e.a("LoginStatSender", new Object[] { "sendStat Entry! from type :  " + paramString });
        if (TextUtils.isEmpty(paramString))
            return;
        if (!(a())) {
            e.a("LoginStatSender", new Object[] { "need not send stat!" });
            return;
        }
        new Thread(paramString) {
            public void run() {
                StringBuilder localStringBuilder = new StringBuilder();
                localStringBuilder.append("http://relation.gamebox.360.cn/system/login?");
                localStringBuilder.append("from=" + com.qihoo.gamecenter.sdk.common.e.a.a(d.a(d.this)));
                localStringBuilder.append("&");
                localStringBuilder.append("pagetype=" + this.a);
                localStringBuilder.append("&");
                localStringBuilder.append("mid=" + d.b(d.this));
                localStringBuilder.append("&");
                localStringBuilder.append("appid="
                        + com.qihoo.gamecenter.sdk.login.plugin.h.a.a(d.a(d.this), d.c(d.this)));
                String str1 = localStringBuilder.toString();
                e.a("LoginStatSender", new Object[] { "stat url: " + str1 });
                String str2 = com.qihoo.gamecenter.sdk.login.plugin.d.a.a(d.a(d.this), str1);
                e.a("LoginStatSender", new Object[] { "stat res: " + str2 });
                try {
                    JSONObject localJSONObject = new JSONObject(str2);
                    int i = localJSONObject.optInt("status", -1);
                    if (1 == i) {
                        g.a(d.a(d.this), "login_stat_sended", "true");
                        e.a("LoginStatSender", new Object[] { "send stat ok save flag!" });
                    }
                } catch (Exception localException) {
                    e.b("LoginStatSender", "send stat error!", localException);
                }
            }
        }.start();
    }

    private boolean a() {
        String str = g.d(this.a, "login_stat_sended");
        return (!("true".equals(str)));
    }

    private String b() {
        if (TextUtils.isEmpty(this.c)) {
            this.c = a(this.a);
            if (TextUtils.isEmpty(this.c))
                this.c = b(this.a);
            if (!(TextUtils.isEmpty(this.c)))
                this.c = k.a(this.c);
        }
        if (TextUtils.isEmpty(this.c))
            e.a("LoginStatSender", new Object[] { "mid is empty" });
        else
            e.a("LoginStatSender", new Object[] { "mid is " + this.c });
        return this.c;
    }

    private String a(Context paramContext) {
        TelephonyManager localTelephonyManager = (TelephonyManager) paramContext.getSystemService("phone");
        if (0 == paramContext.getPackageManager().checkPermission("android.permission.READ_PHONE_STATE",
                paramContext.getPackageName()))
            return localTelephonyManager.getDeviceId();
        return null;
    }

    private String b(Context paramContext) {
        String str = null;
        try {
            WifiManager localWifiManager = (WifiManager) paramContext.getSystemService("wifi");
            WifiInfo localWifiInfo = localWifiManager.getConnectionInfo();
            if (localWifiInfo != null)
                str = localWifiInfo.getMacAddress();
        } catch (Exception localException) {}
        return str;
    }
}